package com.bjesc_b2c.app.appraiset.mvp.model.impl;

import android.content.Context;

import com.bjesc_b2c.app.appraiset.bean.CompleteOrderBean;
import com.bjesc_b2c.app.appraiset.http.IApiActivityRequest;
import com.bjesc_b2c.app.appraiset.mvp.model.CompleteOrderModel;
import com.rxretrofit_build.util.MapUtil;

import java.util.HashMap;
import java.util.List;

import rxretrofit_base.model.ShowType;
import rxretrofit_base.model.TokenBean;
import rxretrofit_base.net.BaseSubscriber;
import rxretrofit_base.net.RxRequest;

/**
 * Created by yidong on 2017/8/8.
 */

public class CompleteOrderModelImpl implements CompleteOrderModel {
    private CallBack callBack;

    public CompleteOrderModelImpl(CallBack callBack) {
        this.callBack = callBack;
    }
    @Override
    public void getCompleteOrderList(Context context, int page, int type, String keyword, int status) {
            HashMap<String, Object> build = new MapUtil()
                    .put("page", page)
                    .put("type", type)
                    .put("keyword", keyword)
                    .put("status", status)
                    .build();
            RxRequest.request(ShowType.DISMISS, RxRequest.getClient(context, build).create(IApiActivityRequest.class).getCompleteList(),
                    new BaseSubscriber<TokenBean<List<CompleteOrderBean>>>(context) {
                        @Override
                        public void onSuccess(TokenBean<List<CompleteOrderBean>> o) {
                            if (callBack != null) {
                                callBack.callback(o.getData());
                            }
                        }

                        @Override
                        public void onFailure(Throwable e) {
                            if (callBack != null) {
                                callBack.loadFailure();
                            }
                        }

                        @Override
                        public void onStart() {
                            if (callBack != null) {
                                callBack.loadStart();
                            }
                        }

                        @Override
                        public void onCompleted() {
                            if (callBack != null) {
                                callBack.loadCompleted();
                            }
                        }
                    });

        }

    @Override
    public void getAllOrderList(Context context, int page, int type, String keyword, int status) {
        HashMap<String, Object> build = new MapUtil()
                .put("page", page)
                .put("type", type)
                .put("keyword", keyword)
                .put("examine_status", status)
                .build();
        RxRequest.request(ShowType.DISMISS, RxRequest.getClient(context, build).create(IApiActivityRequest.class).getAllDispatchList(),
                new BaseSubscriber<TokenBean<List<CompleteOrderBean>>>(context) {
                    @Override
                    public void onSuccess(TokenBean<List<CompleteOrderBean>> o) {
                        if (callBack != null) {
                            callBack.callback(o.getData());
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        if (callBack != null) {
                            callBack.loadFailure();
                        }
                    }

                    @Override
                    public void onStart() {
                        if (callBack != null) {
                            callBack.loadStart();
                        }
                    }

                    @Override
                    public void onCompleted() {
                        if (callBack != null) {
                            callBack.loadCompleted();
                        }
                    }
                });
    }

    public interface CallBack {
        void callback(List<CompleteOrderBean> bean);

        void loadStart();

        void loadCompleted();

        void loadFailure();
    }
}
